const methodMap = new Map([
  ['/api/system/login', 'POST'],
  ['/api/bill/create', 'POST'],
  ['/api/bill/setBudget', 'POST'],
  ['/api/bill/list', 'POST'],
  ['/api/bill/getBudget', 'POST']
]);

async function checkMethod(ctx, next) {
  let url = ctx.request.url.split('?')[0];
  if(methodMap.has(url) && ctx.request.method !== methodMap.get(url)){
    ctx.response.status = 405;
    ctx.response.body = {
      code: '405',
      data: null,
      message: 'method not allowed',
    };
  } else {
    await next();
  }
}

module.exports = checkMethod;
